import {api} from '@/api/sysSetting'
import renderUrl from '@/api/apiHost'
import request from '@/plugins/request';

const param = (url, data) => {
  const str = Object.keys(data).reduce((result, key, index, arr) => {
    result += `${key}=${data[key]}${(index !== arr.length - 1) ? '&' : ''}`
    return result
  }, '')
  return url + '?' + str
}

export const post = async (apiUrl, params) => api.post(
  `${renderUrl('profile')}/profile${apiUrl}`,
  params
).then(res => res.result)

export const get = async (url, params) => api.get(
  `${renderUrl('profile')}/profile${url}`,
  params
).then(resp => resp.result)

export const get1 = async (params) => request({
  method: 'get',
  url: renderUrl('utiltools') + '/support/file/download?fileUrl=' + params,
  responseType: 'arraybuffer'
}).then(resp => resp.data)

export const axiosAll = async arr => {
  return Promise.all(arr)
}

export const missingDataTaskXHR = async (apiUrl,params,type = 'post') => {
  return api[type](`${renderUrl('profile')}/profile/dataCommu/${apiUrl}`,params).then(res => res.result)
}